package com.advm.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.advm.bean.Resources;


public class MySQLConn {
	public String url = Resources.mysql_url;
    public String username = Resources.mysql_user;  
    public String password = Resources.mysql_psw;  
    
    public static MySQLConn instance = null;
    static{
    	 try {
			Class.forName(Resources.mysql_driver);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	public MySQLConn() {
	}
	public static MySQLConn getInstance() {
		synchronized (MySQLConn.class) {
			if(instance == null)
			{
				instance = new MySQLConn();
			}
		}
		return instance;
	}
	
    public Connection getConnection() throws SQLException
    {
    	return DriverManager.getConnection(url, username, password);
    }
	public void free(Connection conn,Statement st,ResultSet rs) 
	{
		  try {  
	            if (rs != null) {  
	                rs.close();  
	            }  
	        } catch (SQLException e) {  
	            e.printStackTrace();  
	        } finally {  
	            try {  
	                if (st != null) {  
	                    st.close();  
	                }  
	            } catch (SQLException e) {  
	                e.printStackTrace();  
	            } finally {  
	                try {  
	                    if (conn != null) {  
	                        conn.close();  
	                    }  
	                } catch (SQLException e) {  
	                    e.printStackTrace();  
	                }  
	            }  
	        }  
	}
    
    
}
